const { argv } = require('yargs')

const isDev = argv.config.includes('dev')

const plugins = [
  [
    '@babel/plugin-transform-runtime',
    {
      useESModules: true,
    },
  ],
]

module.exports = (api) => {
  api.cache(true)
  return {
    presets: [
      [
        '@babel/preset-env',
        {
          modules: false,
        },
      ],
      [
        '@babel/preset-react',
        {
          runtime: 'automatic',
        },
      ],
      '@babel/preset-typescript',
    ],
    plugins: isDev ? [...plugins, 'react-refresh/babel'] : [...plugins],
  }
}
